use "${datadir}\HCA_full.dta", clear
keep if dated <= mdy(4, 2, 2015)
merge 1:1 schemeid using ///
	"${datadir}\HCA_redemptions_all", keep(1 3) ///
	keepusing(Datepurchased HCACash OriginalHCAshare Transactiontype ///
	Completion merge_htb_main) gen(merge_repaid)


*--- merge in appreciation data
// Match the local authorities
merge m:1 pcd using ///
	"${datadir}\la_region_postcode_lookup", ///
	keep(1 3) nogen
ren localauthoritycode areacode 




// Appreciation new
gen dateq = qofd(dated) + 8 
ren areacode laua
merge m:1 dateq laua using ///
	"${datadir}\la_prevnew_appreciation", keep(1 3) 
// same matching results as above (43,028)
ren dateq dateq2y
gen dateq = dateq - 8



*--- Add data on non-EL properties
gen original = 1
append using "${datadir}\HTB_main"
keep if dateq <= yq(2015,1) | original == 1
keep if htb_dummy==0 | original == 1



// idiosyncratic appreciation: sales
gen dhpn = (appreciation2new + 1)^(1/2) - 1
replace dhpn = dhpn * 100

gen diff = Completion - Datepurchased
gen dhp_a = HCACash / OriginalHCAshare 
gen diff_year = diff / 365
gen appr = ( dhp_a^(1 / diff_year ) - 1 ) * 100



	
*------------------------------------------------------------------------------*
* Comparison with full sample *
*------------------------------------------------------------------------------*

replace htb_dummy = 1 if original == 1
	

ttest dhpn, by(htb_dummy)


*------------------------------------------------------------------------------*
* Government return *
*------------------------------------------------------------------------------*

keep if original == 1

// EL not repaid
sum dhpn if mi(appr)

// EL repaid
gen return = appr 

sum return , d
sum return if regexm(Transactiontype, "Sale"), d
sum return if regexm(Transactiontype, "staircasing"), d

ttest return==dhpn 
ttest return==dhpn if regexm(Transactiontype, "Sale")
ttest return==dhpn if regexm(Transactiontype, "staircasing")